//
//  AssistClass.m
//  Billing
//
//  Created by Dale on 17/4/21.
//  Copyright © 2017年 Nari. All rights reserved.
//

#import "AssistClass.h"

@implementation AssistClass

+ (BOOL)validateMoney:(NSString *)money {
    NSString *phoneRegex = @"^[0-9]+(\\.[0-9]{1,2})?$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:money];
}

+ (BOOL)isNumText:(NSString *)str {
    NSString * regex        = @"(/^[0-9]*$/)";
    NSPredicate * pred      = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch            = [pred evaluateWithObject:str];
    if (isMatch) {
        return YES;
    }else{
        return NO;
    }
}


+ (BOOL)isPureFloat:(NSString*)string {
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    
    float val;
    
    return[scan scanFloat:&val] && [scan isAtEnd];
    
}


//检测改变过的文本是否匹配正则表达式，如果匹配表示可以键入，否则不能键入
+ (BOOL) isValid:(NSString*)checkStr {
    NSString *regex = @"^\\-?([1-9]\\d*|0)(\\.\\d{0,2})?$";
    NSPredicate *predicte = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    return [predicte evaluateWithObject:checkStr];
}

@end
